<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>修改密码</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vant@1.6/lib/index.css">
		<!-- 引入组件 -->
		<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.min.js"></script>
		<script src="https://cdn.jsdelivr.net/npm/vant@1.6/lib/vant.min.js"></script>
		<script src="html5plus://ready"></script>
		<script src="../../js/ajax.js"></script>
		<script type="text/javascript" src="../../js/fanhui.js" ></script>
	</head>
	<body>
		<div id="app">
			<header>
				<van-row style="background-color: #FF4444;color: white;">
					<van-col span="9">
						<p @click="onClickLeft"> 
							<van-icon name="arrow-left"/>
						</p>
					</van-col>
					<van-col span="10">
						<p>修改登录密码</p>
					</van-col>
					<van-col span="5">
						<p @click="queren()">确认修改</p>
					<van-col>
				</van-row>
			</header>
			<section>
				<van-field center clearable placeholder="6位数字短信验证码" v-model="code">
					<van-button slot="button" size="small" type="danger" @click="oncode">发送验证码</van-button>
				</van-field>
				<van-field center v-model="pwd" type="password" clearable placeholder="请输入新的登陆密码">
					
				</van-field>
				<van-field center v-model="ispwds" type="password" clearable placeholder="再次输入新的登陆密码">
					
				</van-field>
				<van-icon name="info-o" style="font-size: 12px;font-weight: bold;margin-top: 20px;margin-left: 10px;">系统将会向您绑定的手机号发送一条短信.</van-icon>
			</section>
		</div>
	</body>
	<script>
		var user=plus.storage.getItem("user");
		user=JSON.parse(user);
		var vm = new Vue({
			el: "#app",
			data:{
				code:'',//输入的验证码
				sendcode:'',//正确验证码
				pwd:'',//新密码
				ispwds:''//确认密码
			},
			methods:{
				onClickLeft: function() { //返回个人中心
					plus.webview.close(plus.webview.currentWebview(), "slide-out-left");
				},
				oncode(){
					if(vm.sendcode==""){
						ajax({//发验证码
							url:"http://dsapi.ysd3g.com/API/SendChangePasswordCode ",
							data:{
								key:user.Key
							},
							dataType:'jsonp',
							success:function(res){
								if(res.Error==true)
								{
									vm.$toast(res.Msg);
									return;
								}
								vm.sendcode=res.Code;
								vm.$dialog.confirm({
										title: '验证码',
										message: res.Code,
										confirmButtonText: '一键复制'
									}).then(() => {
										//一键复制
									}).catch(() => {
										//取消
									});
							}
						});
					}else{
						vm.$toast("你的验证码为"+vm.sendcode);
					}
				},
				queren(){//修改
					if(this.pwd==""||this.ispwds==""){
						vm.$toast('输入错误!');
					}else{
						ajax({//发现验证码
							url:"http://dsapi.ysd3g.com/API/ChangePassword ",
							data:{
								key:user.Key,
								password:vm.pwd,
								phoneCode:vm.code
							},
							dataType:'jsonp',
							success:function(res){
								if(res.Error==true)
								{
									vm.$toast(res.Msg);
									return;
								}
								vm.$toast.success("修改成功!你的新密码为"+vm.pwd);
								plus.webview.close("xiugai");
								var login = plus.webview.create("Login.html",login);
								login.show();
								plus.webview.close(plus.webview.currentWebview(), "slide-out-left");
								console.log(res);
							}
						});
					}
					
				}
			}
		})
	</script>
</html>
